/*
 * Copyright (C) 2013 Daniel Treffenstädt <daniel@treffenstaedt.de>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 * 02110-1301  USA
 */

#include "OFace.h"

#include "../Core/OLog.h"

O_START_NAMESPACE

Face::Face() :
	m_dimension(4)
{
	m_height		= new short*[m_dimension];
	m_traversion	= new bool*[m_dimension];
	for (int i = 0; i < m_dimension; i++)
	{
		m_height[i]		= new short[m_dimension];
		m_traversion[i]	= new bool[m_dimension];
	}
	m_visible		= false;
	m_position		= Position::Top;
}

Face::Face(short dimension, Position p, bool visible) :
	m_dimension(dimension)
{
	m_height		= new short*[m_dimension];
	m_traversion	= new bool*[m_dimension];
	for (int i = 0; i < m_dimension; i++)
	{
		m_height[i]		= new short[m_dimension];
		m_traversion[i]	= new bool[m_dimension];
	}
	m_visible		= visible;
	m_position		= p;
	m_base			= 0;
	m_top			= 0;
}

Face::Face(short dimension, short **height, bool **traversion, Position p, short base, short top, bool visible) :
	m_dimension(dimension)
{
	m_height		= height;
	m_traversion	= traversion;
	m_visible		= visible;
	m_position		= p;
	m_base			= base;
	m_top			= top;
}

Face::~Face()
{
	for (int i = 0; i < m_dimension; i++)
	{
		delete m_height[i];
		delete m_traversion[i];
	}
	delete m_height;
	delete m_traversion;
}

bool Face::visible()
{
	return m_visible;
}

void Face::setVisible(bool state)
{
	m_visible	= state;
}

Face::Position Face::position()
{
	return m_position;
}

void Face::setPosition(Position p)
{
	m_position	= p;
}

short Face::heightAt(int x, int y)
{
	if (x >= m_dimension || y >= m_dimension || x < 0 || y < 0)
	{
		error("Trying to access an element outside the face.");
		return 0;
	}
	return m_height[x][y];
}

void Face::setHeight(int x, int y, short value)
{
	if (x >= m_dimension || y >= m_dimension || x < 0 || y < 0)
	{
		error("Trying to access an element outside the face.");
		return;
	}
	m_height[x][y]	= value;
}

bool Face::getTraversion(int x, int y)
{
	if (x >= m_dimension || y >= m_dimension || x < 0 || y < 0)
	{
		error("Trying to access an element outside the face.");
		return false;
	}
	return m_traversion[x][y];
}

void Face::setTraversion(int x, int y, bool t)
{
	if (x >= m_dimension || y >= m_dimension || x < 0 || y < 0)
	{
		error("Trying to access an element outside the face.");
		return;
	}
	m_traversion[x][y]	= t;
}

void Face::setBase(short base)
{
	m_base	= base;
}

void Face::setTop(short top)
{
	m_top	= top;
}

short Face::base()
{
	return m_base;
}

short Face::top()
{
	return m_top;
}

O_END_NAMESPACE
